home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / misc / felix / source / startup.c < prev    next >
C/C++ Source or Header  |  1999-01-25  |  4KB  |  207 lines

  1. //*************************************************************************//
  2. // Filename:    StartUp.c
  3. // Autor:       Christian Taulien of Strange Intelligence
  4. // Purpose:     Library startup-code and function table definition
  5. // Creation:    18. März 1998
  6. //*************************************************************************//
  7. #include "global.h"
  8. #include "FelixBase.h"
  9. #include "processcomm.h"
  10. #include "funcs.h"
  11. #include "flxclasses.h"
  12. #include "freshlocale.h"
  13. //*/ // Für GoldED 5 aktivieren
  14. #include "golded:developer/api/include/apilib.h"
  15. /*/ // Für GoldED 4 aktivieren
  16. #include "golded:developer/api/include/api.h"
  17. //*/
  18.  
  19. #include <exec/exec.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/dos_protos.h>
  23.  
  24. extern "C" void CleanupModules();
  25. extern "C" void InitModules();
  26.  
  27. extern ULONG SAVEDS L_OpenLibs(void);
  28. extern void  SAVEDS L_CloseLibs(void);
  29.  
  30. struct FelixBase *SAVEDS InitLib(register __a6 struct ExecBase *sysbase,
  31.                                     register __a0 APTR           *seglist,
  32.                                     register __d0 struct FelixBase *exb);
  33. struct FelixBase *SAVEDS OpenLib(register __a6 struct FelixBase *FelixBase);
  34. APTR   SAVEDS   CloseLib(register __a6 struct FelixBase *FelixBase);
  35. APTR   SAVEDS ExpungeLib(register __a6 struct FelixBase *exb);
  36. ULONG  ExtFuncLib(void);
  37.  
  38. APTR glob_SegList = NULL;
  39.  
  40. LONG LibStart(void)
  41. /*S*/
  42. {
  43.   return(-1);
  44. }
  45. /*E*/
  46. void _abort__STANDARD()
  47. /*S*/
  48. {
  49. }
  50. /*E*/
  51. void exit(void)
  52. /*S*/
  53. {
  54.   CleanupModules();
  55. }
  56. /*E*/
  57.  
  58. extern APTR FuncTab [];
  59. extern struct MyDataInit DataTab;
  60.  
  61. struct InitTable                     /* do not change! */
  62. {
  63.  ULONG              LibBaseSize;
  64.  APTR              *FunctionTable;
  65.  struct MyDataInit *DataTable;
  66.  APTR               InitLibTable;
  67. } InitTab =
  68. {
  69.  sizeof(struct FelixBase),
  70.  &FuncTab[0],
  71.  &DataTab,
  72.  InitLib
  73. };
  74.  
  75. APTR FuncTab [] =                      
  76. {
  77.  OpenLib,
  78.  CloseLib,
  79.  ExpungeLib,
  80.  ExtFuncLib,
  81.  
  82.   APIMountClient,
  83.   APICloseClient,
  84.   APIBriefClient,
  85.   APIFree,
  86.  
  87.  (APTR) ((LONG)-1)
  88. };
  89.  
  90. extern struct FelixBase *FelixBase;
  91.  
  92. FLXWatchListC *glob_poWatches = NULL;
  93.  
  94. struct FelixBase * SAVEDS InitLib( register __a6 struct ExecBase *sysbase,
  95.                                    register __a0 APTR           *seglist,
  96.                                    register __d0 struct FelixBase *apib)
  97. /*S*/
  98. {
  99.   InitModules();
  100.   TRACE("");
  101.   FelixBase = apib;
  102.   glob_SegList = seglist;
  103.  
  104.   if (L_OpenLibs())
  105.   {
  106.     glob_sReturnBuffer = new char [1000];
  107.     glob_poCatalog = new CatalogC("felix.catalog", 1);
  108.  
  109.     ((struct FelixBase *)FelixBase)->api_Magic = API_MAGIC;
  110.     glob_poWatches = new FLXWatchListC;
  111.  
  112.     StarteProzess();
  113.  
  114.     return(FelixBase);
  115.   }
  116.   L_CloseLibs();
  117.  
  118. return NULL;
  119. }
  120. /*E*/
  121. struct FelixBase * SAVEDS OpenLib(register __a6 struct FelixBase *FelixBase)
  122. /*S*/
  123. {
  124.   TRACE("");
  125.   FelixBase->api_LibNode.lib_OpenCnt++;
  126.   FelixBase->api_LibNode.lib_Flags &= ~LIBF_DELEXP;
  127. return FelixBase;
  128. }
  129. /*E*/
  130. APTR SAVEDS CloseLib(register __a6 struct FelixBase *FelixBase)
  131. /*S*/
  132. {
  133.   TRACE("");
  134.   FelixBase->api_LibNode.lib_OpenCnt--;
  135.   if (!FelixBase->api_LibNode.lib_OpenCnt)
  136.   {
  137.      if (FelixBase->api_LibNode.lib_Flags & LIBF_DELEXP)
  138.      {
  139.        return ExpungeLib(FelixBase);
  140.      } // if
  141.   } // if
  142.   return NULL;
  143. }
  144. /*E*/
  145. APTR SAVEDS ExpungeLib(register __a6 struct FelixBase *api)
  146. /*S*/
  147. {
  148.  TRACE("");
  149.  struct FelixBase *FelixBase = api;
  150.  APTR seglist;
  151.  
  152.   if (!FelixBase->api_LibNode.lib_OpenCnt)
  153.   {
  154.     ULONG negsize, possize, fullsize;
  155.     UBYTE *negptr = (UBYTE *) FelixBase;
  156.  
  157.     seglist = glob_SegList;
  158.  
  159.     if (glob_sReturnBuffer)
  160.     {
  161.       delete glob_sReturnBuffer;
  162.       glob_sReturnBuffer = NULL;
  163.     } // if
  164.  
  165.     if (glob_poWatches)
  166.     {
  167.       delete glob_poWatches;
  168.       glob_poWatches = NULL;
  169.     } // if
  170.  
  171.     BeendeProzess();
  172.  
  173.     Remove((struct Node *)FelixBase);
  174.  
  175.     if (glob_poCatalog)
  176.     {
  177.       delete glob_poCatalog;
  178.       glob_poCatalog = NULL;
  179.     } // if
  180.  
  181.     L_CloseLibs();
  182.  
  183.     negsize  = FelixBase->api_LibNode.lib_NegSize;
  184.     possize  = FelixBase->api_LibNode.lib_PosSize;
  185.     fullsize = negsize + possize;
  186.     negptr  -= negsize;
  187.  
  188.     FreeMem(negptr, fullsize);
  189.     CleanupModules();
  190.     return seglist;
  191.   }
  192.   
  193.  FelixBase->api_LibNode.lib_Flags |= LIBF_DELEXP;
  194.  
  195. return NULL;
  196. }
  197. /*E*/
  198. ULONG ExtFuncLib(void)
  199. /*S*/
  200. {
  201. return NULL;
  202. }
  203. /*E*/
  204.  
  205. struct FelixBase *FelixBase = NULL;
  206.  
  207.